package com.lxl;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

public class MessageSend {
    public static void main(String[] args) {
        String sentence = "hi,小雪";
        Robot robot = null;
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
        robot.delay(2000);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        //根据字符串分割
        String[] authon = sentence.split("[,]");
        for (int j = 0; j < 3; j++) {
            for (int i = 0; i < authon.length; i++) {
                String sentences = authon[i];
                StringSelection stringSelection = new StringSelection(sentences);
                clipboard.setContents(stringSelection, null);
                robot.keyPress(KeyEvent.VK_CONTROL);// 按下Control键
                robot.keyPress(KeyEvent.VK_V);// 按下V键
                robot.keyRelease(KeyEvent.VK_CONTROL);// 释放ctrl按键
                robot.delay(100);// 延迟一秒再发送
                robot.keyPress(KeyEvent.VK_ENTER);// 回车
            }
        }
    }
}
